package com.xqb.modules.controller.course;

import com.xqb.common.annotation.Log;
import com.xqb.common.core.controller.BaseController;
import com.xqb.common.core.domain.AjaxResult;
import com.xqb.common.core.page.TableDataInfo;
import com.xqb.common.enums.BusinessType;
import com.xqb.common.utils.poi.ExcelUtil;
import com.xqb.modules.domain.po.LesCourseCataSubject;
import com.xqb.modules.service.ILesCourseCataSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 课程-题目关系Controller
 * 
 * @author xqb
 * @date 2024-10-14
 */
@RestController
@RequestMapping("/course/course_subject")
public class LesCourseCataSubjectController extends BaseController
{
    @Autowired
    private ILesCourseCataSubjectService lesCourseCataSubjectService;

    /**
     * 查询课程-题目关系列表
     */
    @PreAuthorize("@ss.hasPermi('course:course_subject:list')")
    @GetMapping("/list")
    public TableDataInfo list(LesCourseCataSubject lesCourseCataSubject)
    {
        startPage();
        List<LesCourseCataSubject> list = lesCourseCataSubjectService.selectLesCourseCataSubjectList(lesCourseCataSubject);
        return getDataTable(list);
    }

    /**
     * 导出课程-题目关系列表
     */
    @PreAuthorize("@ss.hasPermi('course:course_subject:export')")
    @Log(title = "课程-题目关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LesCourseCataSubject lesCourseCataSubject)
    {
        List<LesCourseCataSubject> list = lesCourseCataSubjectService.selectLesCourseCataSubjectList(lesCourseCataSubject);
        ExcelUtil<LesCourseCataSubject> util = new ExcelUtil<LesCourseCataSubject>(LesCourseCataSubject.class);
        util.exportExcel(response, list, "课程-题目关系数据");
    }

    /**
     * 获取课程-题目关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('course:course_subject:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(lesCourseCataSubjectService.selectLesCourseCataSubjectById(id));
    }

    /**
     * 新增课程-题目关系
     */
    @PreAuthorize("@ss.hasPermi('course:course_subject:add')")
    @Log(title = "课程-题目关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LesCourseCataSubject lesCourseCataSubject)
    {
        return toAjax(lesCourseCataSubjectService.insertLesCourseCataSubject(lesCourseCataSubject));
    }

    /**
     * 修改课程-题目关系
     */
    @PreAuthorize("@ss.hasPermi('course:course_subject:edit')")
    @Log(title = "课程-题目关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LesCourseCataSubject lesCourseCataSubject)
    {
        return toAjax(lesCourseCataSubjectService.updateLesCourseCataSubject(lesCourseCataSubject));
    }

    /**
     * 删除课程-题目关系
     */
    @PreAuthorize("@ss.hasPermi('course:course_subject:remove')")
    @Log(title = "课程-题目关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(lesCourseCataSubjectService.deleteLesCourseCataSubjectByIds(ids));
    }
}
